Write-Host "测试 SmartMedicalRAG.Api 端点..." -ForegroundColor Green

$baseUrl = "https://localhost:56704"

# 测试根路径
Write-Host "`n1. 测试根路径重定向..." -ForegroundColor Yellow
try {
    $response = Invoke-WebRequest -Uri $baseUrl -Method GET -SkipCertificateCheck
    Write-Host "✓ 根路径重定向成功" -ForegroundColor Green
} catch {
    Write-Host "✗ 根路径重定向失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试主页
Write-Host "`n2. 测试主页端点..." -ForegroundColor Yellow
try {
    $response = Invoke-WebRequest -Uri "$baseUrl/home" -Method GET -SkipCertificateCheck
    $content = $response.Content | ConvertFrom-Json
    Write-Host "✓ 主页端点正常: $($content.Application)" -ForegroundColor Green
} catch {
    Write-Host "✗ 主页端点失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试健康检查
Write-Host "`n3. 测试健康检查端点..." -ForegroundColor Yellow
try {
    $response = Invoke-WebRequest -Uri "$baseUrl/api/triage/health" -Method GET -SkipCertificateCheck
    $content = $response.Content | ConvertFrom-Json
    Write-Host "✓ 健康检查正常: $($content.Status)" -ForegroundColor Green
} catch {
    Write-Host "✗ 健康检查失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试 Swagger
Write-Host "`n4. 测试 Swagger UI..." -ForegroundColor Yellow
try {
    $response = Invoke-WebRequest -Uri "$baseUrl/swagger" -Method GET -SkipCertificateCheck
    if ($response.Content -like "*swagger*") {
        Write-Host "✓ Swagger UI 正常" -ForegroundColor Green
    } else {
        Write-Host "✗ Swagger UI 响应异常" -ForegroundColor Red
    }
} catch {
    Write-Host "✗ Swagger UI 失败: $($_.Exception.Message)" -ForegroundColor Red
}

# 测试分诊分析端点
Write-Host "`n5. 测试分诊分析端点..." -ForegroundColor Yellow
$testData = @{
    ChiefComplaint = "胸痛"
    Symptoms = @("胸痛", "呼吸困难")
    TextData = "患者主诉胸痛，伴有呼吸困难"
} | ConvertTo-Json

try {
    $response = Invoke-WebRequest -Uri "$baseUrl/api/triage/analyze" -Method POST -Body $testData -ContentType "application/json" -SkipCertificateCheck
    $content = $response.Content | ConvertFrom-Json
    Write-Host "✓ 分诊分析正常: 推荐科室 $($content.Recommendation.RecommendedDepartment)" -ForegroundColor Green
} catch {
    Write-Host "✗ 分诊分析失败: $($_.Exception.Message)" -ForegroundColor Red
}

Write-Host "`n测试完成！" -ForegroundColor Green
Write-Host "您可以访问以下地址：" -ForegroundColor Cyan
Write-Host "  - 主页: $baseUrl" -ForegroundColor Cyan
Write-Host "  - Swagger UI: $baseUrl/swagger" -ForegroundColor Cyan
Write-Host "  - 健康检查: $baseUrl/api/triage/health" -ForegroundColor Cyan 